package com.ruoyi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.CategoryOne;
import com.ruoyi.service.ICategoryOneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 一级分类
 */
@RestController
@RequestMapping("/webshop/categoryOne")
public class CategoryOneController extends BaseController {
@Autowired
private ICategoryOneService categoryOneService;

// 全查
@GetMapping("/list")
public List<CategoryOne> list(){
    List<CategoryOne> list = categoryOneService.list();
    return list;
}
@GetMapping("/listCascader")
public AjaxResult listCascader(){
    List<Map<String, Object>> list = categoryOneService.selectListCascader();
    return AjaxResult.success(list);
}
// 根据id查一条
@GetMapping("/{id}")
public CategoryOne getInfo(@PathVariable Long id){
    System.out.println("id = " + id);
    CategoryOne categoryOne = categoryOneService.getById(id);
    return categoryOne;
}
// 添加
@PostMapping()
public int add(@RequestBody CategoryOne categoryOne){
    System.out.println("categoryOne = " + categoryOne);
    int add = categoryOneService.save(categoryOne);
    return add;
}
// 修改
@PutMapping()
public int edit(@RequestBody CategoryOne categoryOne){
    System.out.println("categoryOne = " + categoryOne);
    int edit = categoryOneService.updateById(categoryOne);
    return edit;
}


}
